﻿namespace Multiprocessing.Core.Mathematics.Matrices
{
    public class Matrix : BaseMatrix
    {
        #region Fields

        private double[,] _underlaying;

        #endregion

        public Matrix(int rowCount, int columnCount) 
            : base(rowCount, columnCount)
        {
        }

        protected override void CreateUnderlaying(int row, int column)
        {
            _underlaying = new double[column, row];
        }

        protected override IMatrix CloneMatrix()
        {
            var destionation = new Matrix(this.RowCount, this.ColumnCount);
            CloneMatrix(this, destionation);
            return destionation;
        }

        public override double GetElement(int row, int column)
        {
            return _underlaying[row, column];
        }

        public override void SetElement(int row, int column, double value)
        {
            _underlaying[row, column] = value;
        }

        public override IMatrix Add(IMatrix matrix)
        {
            var result = new Matrix(RowCount, ColumnCount);
            Add(this, matrix, result);
            return result;
        }

        public override IMatrix Substract(IMatrix matrix)
        {
            IMatrix result = new Matrix(RowCount, ColumnCount);
            Substract(this, matrix, result);
            return result;
        }

        public override IMatrix Multiply(IMatrix matrix)
        {
            IMatrix result = new Matrix(this.RowCount, matrix.ColumnCount);
            Multiply(this, matrix, result);
            return result;
        }

        public override IMatrix Multiply(double value)
        {
            IMatrix result = new Matrix(this.RowCount, this.ColumnCount);
            Multiply(this, value, result);
            return result;
        }

        public override IMatrix Divide(double value)
        {
            IMatrix result = new Matrix(this.RowCount, this.ColumnCount);
            Divide(this, value, result);
            return result;
        }
    }
}
